/*
 * Project.java
 *
 * Created on September 6, 2007, 2:53 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 *
 *  Nov, 17, 2011 Modified in order to handle DB patterns.
 *
 */

package portfolio.dbHost.project;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.util.Calendar;
import java.util.Date;
import java.util.Vector;
import javax.swing.JPopupMenu;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import misellanea.Miscellanea;
import portfolio.dbHost.Host;
import portfolio.dbHost.ProjectTreeTab;
import portfolio.dbHost.dataBases.DBase;
import portfolio.dbHost.dataBases.DBaseFactory;
import portfolio.dbHost.dataBases.dbTable.Table;
import portfolio.dbHost.dataBases.dbTable.tblColumn.Column;
import portfolio.dbHost.project.attributes.ExcludeColumns;
import portfolio.dbHost.project.attributes.ExcludeTables;
import portfolio.dbHost.project.attributes.InputAttribs;
import portfolio.dbHost.project.attributes.OptionalAttributes;
import portfolio.dbHost.project.attributes.StockExperiments;
import portfolio.dbHost.project.attributes.TimeLine;
import portfolio.mainScreen;

/**
 *
 * @author ACA
 */
public class Project /*extends DBase*/ implements MouseListener
{
    DBase          projectDBase = null;
    ProjectTreeTab projectTree = null;

    static final public String ASCENDENT_TRADEDATE  = "ASC";
    static final public String DESCENDENT_TRADEDATE = "DESC";
    
    DefaultMutableTreeNode node = null;
    
    InputAttribs       tInputAttribs       = null;
    ExcludeTables      tExcludeTables      = null;
    ExcludeColumns     tExcludeColumns     = null;
    TimeLine           tTimeLine           = null;
    StockExperiments   tStockExperiments   = null;
    OptionalAttributes tOptionalAttributes = null;
    
    JTree              dbaseTree           = null;
    
    /**
     * 
     * @param e 
     */
    public void mouseClicked(MouseEvent e) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mousePressed(MouseEvent e) {
System.out.println ("=============================== DBase: MOUSE PRESSED ========================");        
//        System.out.println ("InputAttribs mouse pressed.");
 //       throw new UnsupportedOperationException("Not supported yet.");
   }

    public void mouseReleased(MouseEvent e) {
 //       throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseEntered(MouseEvent e) {
 //       throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseExited(MouseEvent e) {
//        throw new UnsupportedOperationException("Not supported yet.");
//        e.equals(MouseEvent.BUTTON1);
    }
//    final private String ACTION_PR0JECT    = "Action Project";
    
    /**
     * 
     */
    public Project(Host hostParam, 
                   String sPrjNameParam) throws Exception
    {
        DBaseFactory dbaseFactory = new DBaseFactory ();
        projectDBase = dbaseFactory.getDBType(hostParam);//super (hostParam);
        projectDBase.setDBName(sPrjNameParam);//super.setDBName(sPrjNameParam);

//        if (!Project.isProject(projectDBase.getDBHost().getConnection(), sPrjNameParam)) {
//            projectDBase.getDBHost().createDB(sPrjNameParam);
//        }
        if (!Project.isProject(projectDBase)) {
            projectDBase.getDBHost().createDB(sPrjNameParam);
        }
        tInputAttribs = new InputAttribs (projectDBase);
        if (tInputAttribs == null) {
            throw new Exception ("Error on inputattribs table of project " + sPrjNameParam);
        }

        tExcludeTables = new ExcludeTables (projectDBase);
        if (tExcludeTables == null) {
            throw new Exception ("Error on tablesexclude table of project " + sPrjNameParam);
        }

        tExcludeColumns = new ExcludeColumns (projectDBase);
        if (tExcludeColumns == null) {
            throw new Exception ("Error on columnsexclude table of project " + sPrjNameParam);
        }

        tTimeLine = new TimeLine (this);
        if (tTimeLine == null) {
            throw new Exception ("Error on timeline table of project " + sPrjNameParam);
        }

        tStockExperiments = new StockExperiments (this);
        if (tStockExperiments == null) {
            throw new Exception ("Error on stockExperiments table of project " + sPrjNameParam);
        }

        tOptionalAttributes = new OptionalAttributes (this);
        if (tOptionalAttributes == null) {
             throw new Exception ("Error on optionalAttributes table of project " + sPrjNameParam);
        }

        projectDBase.setTablesVector();
       
        projectDBase.getDBHost().setProject(this);
    }
    /**
     * @param hostParam
     * @throws java.lang.Exception
     * @param sPrjNameParam
     * @param sInputDB
     * @param sIndexColumn
     * @param sTrainSetColumn
     * @param beginDate
     * @param endDate
     * @param ITerm
     * @param sExcludeTables
     * @param sExcludeColumns
     */
    public void initComponents (
                   String    sInputDB,
                   String    sIndexColumn,
                   String    sTrainSetColumn,
                   Calendar  beginDate,
                   Calendar  endDate,
                   Integer   ITerm,
                   String [] sExcludeTables,
                   String [] sExcludeColumns,
                   String    sOptAttrStock,
                   String    sOptRiskFree) throws Exception
    {

        this.validateInputAttributes (sInputDB, sExcludeTables, sIndexColumn, sExcludeColumns, sTrainSetColumn);
        this.validateDateRange       (beginDate, endDate);
        this.validateTerm            (ITerm);

        long   lTmpBeginDate = beginDate.getTimeInMillis();
        java.sql.Date dBeginDate = new java.sql.Date (lTmpBeginDate);
        String sBeginDate = dBeginDate.toString();

        long   lTmpEndDate = endDate.getTimeInMillis();
        java.sql.Date dEndDate = new java.sql.Date (lTmpEndDate);
        String sEndDate = dEndDate.toString();

        tInputAttribs.initComponents(sInputDB, sIndexColumn, sTrainSetColumn);
        tExcludeTables.initComponents(sExcludeTables);
        tExcludeColumns.initComponents(sExcludeColumns);
        tTimeLine.initComponents(sBeginDate, sEndDate, ITerm);
        tStockExperiments.initComponents();
        tOptionalAttributes.initComponents(sOptAttrStock, sOptRiskFree);

        projectDBase.setTablesVector( );

    }
    /**
     *
     *
     */
    public void updateProjectTree () throws Exception
    {
        mainScreen mainFrame = projectDBase.getDBHost().getMainScreen();
        if (mainFrame == null)
            throw new Exception ("null mainFrame");

        projectTree = new ProjectTreeTab (mainFrame.getProjectPanel());
        projectTree.initComponents(this);
        mainFrame.getProjectPanel().revalidate (); //.removeAll(); //0j0  ????
    }
    /**
     *
     */
    public String getProjectName ()
    {
        return projectDBase.getDBName();
    }
    /**
     *
     */
    public DefaultMutableTreeNode processProjectHierarchy ( )
    {
        node = new DefaultMutableTreeNode (projectDBase.getDBName());
        
        DefaultMutableTreeNode nodeInputAttribs     = tInputAttribs.processHierarchy();
        if (nodeInputAttribs != null)
            node.add (nodeInputAttribs);

        DefaultMutableTreeNode nodeExcludeTables    = tExcludeTables.processHierarchy();
        if (nodeExcludeTables != null)
            node.add (nodeExcludeTables);
        
        DefaultMutableTreeNode nodeExcludeColumns   = tExcludeColumns.processHierarchy();
        if (nodeExcludeColumns != null)
            node.add (nodeExcludeColumns);
        
        DefaultMutableTreeNode nodeTimeLine         = tTimeLine.processHierarchy();
        if (nodeTimeLine != null)
            node.add (nodeTimeLine);
        
        DefaultMutableTreeNode nodeStockExperiments = tStockExperiments.processHierarchy();
        if (nodeStockExperiments != null)
            node.add (nodeStockExperiments);

        DefaultMutableTreeNode nodeOptionalAttrbutes = tOptionalAttributes.processHierarchy();
        if (nodeOptionalAttrbutes != null)
            node.add (nodeOptionalAttrbutes);
        
        return (node);
    } /* end method processHierarchy */
    /**
     *
     */
    public InputAttribs getInputAttribs ()
    {
        return tInputAttribs;
    }
    /**
     *
     */
    public ExcludeTables getExcludeTables ()
    {
        return tExcludeTables;
    }
    /**
     *
     */
    public ExcludeColumns getExcludeColumns ()
    {
        return tExcludeColumns;
    }
    /**
     *
     */
    public TimeLine getTimeline ()
    {
        return tTimeLine;
    }
    /**
     * 
     */
    public StockExperiments getStockExperiments ()
    {
        return tStockExperiments;
    }
    /**
     *
     */
    public OptionalAttributes getOptionalAttributes ()
    {
        return tOptionalAttributes;
    }
    /**
     *
     * @param dbTreeParam 
     * @param iXPos 
     * @param iYPos 
     */
    public void getPopupOptions (JTree dbTreeParam, int iXPos, int iYPos)
    {
        dbaseTree = dbTreeParam;       

        JPopupMenu treeOptionsMenu = new JPopupMenu ("Options");
        dbaseTree.add(treeOptionsMenu);
        
        treeOptionsMenu.addMouseListener(this);

        treeOptionsMenu.setLocation (iXPos, iYPos);
        treeOptionsMenu.show (treeOptionsMenu, iXPos, iYPos);

        return;
    } /* end method getPopupOptions */     
    /**
     *
     * @param oPathParam 
     * @return 
     * @throws java.lang.Exception 
     */
    public Object getTreeObject (Object [] oPathParam)
    {
        int iPathLen = oPathParam.length;
        
        if (oPathParam == null) {
            return null; // report error
        }
        if (iPathLen < 1) {
            return null; //report error
        }
        if (iPathLen == 1) {
            String sProjectName = projectDBase.getDBName();
            if (oPathParam [0].toString().equals(/*super.getDBName()*/sProjectName)) {
                return this;
            } else {
                return null; //report error
            }
        }
        
        String sAttribTable = oPathParam[1].toString();
        Vector vTables = projectDBase.showTables();
        if (vTables.contains(sAttribTable)) {
            Object tmpObject = null;
            tmpObject = tInputAttribs.getTreeObject(oPathParam);
            if (tmpObject != null)
                return tmpObject;
            tmpObject = tExcludeTables.getTreeObject(oPathParam);
            if (tmpObject != null)
                return tmpObject;
            tmpObject = tExcludeColumns.getTreeObject(oPathParam);
            if (tmpObject != null)
                return tmpObject;
            tmpObject = tTimeLine.getTreeObject(oPathParam);
            if (tmpObject != null)
                return tmpObject;
            tmpObject = tStockExperiments.getTreeObject(oPathParam);
            if (tmpObject != null)
                return tmpObject;
            return tOptionalAttributes.getTreeObject(oPathParam);
        } 
        
        return null;
    } /* end method getTreeObject */
    /**
     *
     */
    private void validateInputAttributes (String    sTmpInputDB, 
                                          String [] sExcludeTables, 
                                          String    sIndexColumn, 
                                          String [] sExcludeColumns,
                                          String    sTrainSetColumn) throws Exception
    {
        if (sTmpInputDB == null || sTmpInputDB.equals ("")) {
            throw new Exception ("Error: invalid inputDB  name attribute.");
        }
        Host host = projectDBase.getDBHost();
        Connection connection = host.getConnection();

        Vector vTmpTables = host.getDB(sTmpInputDB).showTables();
        if (vTmpTables == null || vTmpTables.size() < 2) {
            throw new Exception ("Error: invalid inputDB  " + sTmpInputDB + " is not a valid inputDB.");
        }
        
        int iExcludeTablesSize = 0;
        if (sExcludeTables != null && !sExcludeTables [0].equals ("")) {
            iExcludeTablesSize = sExcludeTables.length;
        }
        if (sExcludeColumns == null || sExcludeColumns[0].equals ("")) {
            throw new Exception ("Error: invalid ExcludeColumns  names attibute.");
        }
        if (sIndexColumn == null || sIndexColumn.equals ("")) {
            throw new Exception ("Error: invalid indexColumn  name attibute.");
        }
        if (sTrainSetColumn == null || sTrainSetColumn.equals ("")) {
            throw new Exception ("Error: invalid trainSet  name attibute.");            
        }
        String sSampleTable = vTmpTables.get(0).toString();
        Column columnTmp = host.getDB(sTmpInputDB).getTable(sSampleTable).getColumnDescriptionIgnoreCase (sTrainSetColumn);
        if (columnTmp == null) {            
            throw new Exception ("Error: invalid trainSet  " + sTrainSetColumn + ".");            
        }
                                
        for (int i = 0; i < iExcludeTablesSize; i++) {
            if (!vTmpTables.contains (sExcludeTables [i])) {
                throw new Exception ("Error: InputDB " + sTmpInputDB + " does not coutains " + sExcludeTables [i] + " exclude table.");
            } else {
System.out.println ("{{{{{{{{{{{{{ WARNING: check that this describe is working OK, it was changed from the original with 2 arguments. }}}}}}}}}}}}}");            
                Vector vTmpColumns = Table.describe (/*super.*/connection, sTmpInputDB, sExcludeTables [i], null);
                if (!Miscellanea.stringVectorContainsIgnoreCase (vTmpColumns, sIndexColumn)) {
                    throw new Exception ("Error: exclude table " + sExcludeTables [i] + " does not contains " + 
                                             sIndexColumn + " index.");
                }
                vTmpTables.remove(sExcludeTables [i]);
            }
        }
        
        int iSize = vTmpTables.size();
        for (int i = 0; i < iSize; i++) {
            boolean bIsExcludeColumn = false;
            String sTmpTable = vTmpTables.get(i).toString();
System.out.println ("{{{{{{{{{{{{{ WARNING: check that this describe is working OK, it was changed from the original with 2 arguments. }}}}}}}}}}}}}");            
            Vector vTmpColumns = Table.describe (/*super.*/connection, sTmpInputDB, sTmpTable, null);
            if (!Miscellanea.stringVectorContainsIgnoreCase(vTmpColumns, sIndexColumn)) {
                throw new Exception ("Error: table " + sTmpTable + " does not contains " + sIndexColumn + " index.");
            }
            int iExcludeColsSize = sExcludeColumns.length;
            for (int j = 0; j < iExcludeColsSize; j++) {
                if (!Miscellanea.stringVectorContainsIgnoreCase(vTmpColumns, sExcludeColumns [j])) {
                    throw new Exception ("Error: table " + sTmpTable + " does not contains " + sExcludeColumns [j] + " excludeColumn.");
                }
            }
            if (!Miscellanea.stringVectorContainsIgnoreCase(vTmpColumns, sTrainSetColumn)) {
                throw new Exception ("Error: table " + sTmpTable + " does not contains " + sTrainSetColumn + " trainSet.");
            }
        }
    }    
    /**
     *
     */
    private Boolean validateDateRange (Calendar beginDateParam, Calendar endDateParam) throws Exception
    {        
        if (!beginDateParam.before (endDateParam)) {
            throw new Exception ("Error while trying to set DateRange: " + "endDate predates to beginDate.");
        }
        
        return true;
    }  
    /**
     *
     */
    private void validateTerm (Integer ITermParam) throws Exception
    {   
        if (ITermParam == null) {
            throw new Exception ("Error: null Term.");            
        }
 
        if (ITermParam.intValue() < 0) {
            throw new Exception ("Error: Term must be positive.");
        }

        return;
    }  
    /**
     *
     */
//    static public Calendar [] setExtremeIndexDates (Connection connectionParam, String sDataBaseParam, String sIndexColumnParam) throws Exception
//    {
//        try {
//            if (connectionParam == null) {
//                throw new Exception ("Error: null connection.");
//            }
//            if (sDataBaseParam == null) {
//                throw new Exception ("Error: null Data Base Name.");
//            }
//            if (sIndexColumnParam == null) {
//                throw new Exception ("Error: null Index Column.");
//            }
//            
//            String sDataBase      = sDataBaseParam;
//            String sIndexColumn   = sIndexColumnParam;
//
//            Calendar tmpBeginDate = Project.getExtremeStockDBTradeDate (connectionParam, sDataBase, sIndexColumn, Project.ASCENDENT_TRADEDATE);
//            Calendar tmpEndDate   = Project.getExtremeStockDBTradeDate (connectionParam, sDataBase, sIndexColumn, Project.DESCENDENT_TRADEDATE);
//            
//            Calendar [] extremeDates = new Calendar [2];
//            extremeDates [0] = tmpBeginDate;
//            extremeDates [1] = tmpEndDate;
//            
//            return extremeDates;
//        } catch (Exception ex) {
//            throw new Exception (ex);
//        }            
//    }
    static public Calendar [] setExtremeIndexDates (Host hostParam, String sDataBaseParam, String sIndexColumnParam) throws Exception
    {
        try {
            if (hostParam == null) {
                throw new Exception ("Error: null connection.");
            }
            if (sDataBaseParam == null) {
                throw new Exception ("Error: null Data Base Name.");
            }
            if (sIndexColumnParam == null) {
                throw new Exception ("Error: null Index Column.");
            }
            
            String sDataBase      = sDataBaseParam;
            String sIndexColumn   = sIndexColumnParam;

            DBase dbase = hostParam.getDB(sDataBase);
            Calendar tmpBeginDate = Project.getExtremeStockDBTradeDate (dbase, sDataBase, sIndexColumn, Project.ASCENDENT_TRADEDATE);
            Calendar tmpEndDate   = Project.getExtremeStockDBTradeDate (dbase, sDataBase, sIndexColumn, Project.DESCENDENT_TRADEDATE);
            
            Calendar [] extremeDates = new Calendar [2];
            extremeDates [0] = tmpBeginDate;
            extremeDates [1] = tmpEndDate;
            
            return extremeDates;
        } catch (Exception ex) {
            throw new Exception (ex);
        }            
    }
    /**
     *
     * @param connectionParam
     * @param sStockDB
     * @param sTradeDate
     * @param sExtreme
     * @return
     * @throws Exception
     */
//    public static Calendar getExtremeStockDBTradeDate (Connection connectionParam,
//                                                       String sStockDB,
//                                                       String sTradeDate,
//                                                       String sExtreme) throws Exception
//    {
//        if (connectionParam == null)
//            throw new Exception ("null connection");
//
//        DBase.useDB(connectionParam, sStockDB);
//
//        Vector vStockTables = DBase.showTables (connectionParam, sStockDB);
//
//        if (vStockTables == null) {
//            throw new Exception ("vStockTables == null");
//        }
//        String sBeginDate = null;
//
//        if (vStockTables.size() >= 1) {
//            int iIdx = 0;
//            String sPrevBeginDate = null;
//            do {
//                String sStockName = vStockTables.get (iIdx).toString ();
////                ResultSet resultSet =  statement.executeQuery ("SELECT " + sTradeDate +
////                                                               " FROM " + sStockName +
////                                                               " ORDER BY " + sTradeDate + " " + sExtreme +
////                                                               " LIMIT 1;");
//                ResultSet resultSet = Table.getQuery(connectionParam, sTradeDate, sStockName, DBase.SQL_TRUE, sTradeDate + " " + sExtreme, " 1 ");
//                if (resultSet.getWarnings() == null) {
//                    resultSet.first();
//                    sBeginDate     = resultSet.getString (sTradeDate).toLowerCase();
//                    if (iIdx == 0) {
//                        sPrevBeginDate = sBeginDate;
//                    }
//                    if (sPrevBeginDate.equals(sBeginDate) == false) {
//                        String sPrevStockName = null;
//                        if (iIdx > 0)
//                            sPrevStockName = (String) vStockTables.get (iIdx -1);
//                        String sErrMsg = "Inconsistent tradeDate index columns on " + sStockDB + " DB; " +
//                                         "date found on " + sPrevStockName + ": " + sPrevBeginDate + ", " +
//                                         "date found on " + sStockName     + ": " + sBeginDate + ".";
//                        throw new Exception (sErrMsg);
//                    }
//                    sPrevBeginDate = sBeginDate;
//                }
//                else {
//                    SQLWarning sqlWarning =resultSet.getWarnings();
//                    String sWarningMsg = sqlWarning.getMessage();
//                    throw new Exception (sWarningMsg);
//                }
//                iIdx++;
//            } while (iIdx < vStockTables.size ());
//        }
//        else {
//            throw new Exception ("vStockTables.size < 1.");
//        }
//
//        Date tmpDate = java.sql.Date.valueOf (sBeginDate);
//
//        Calendar outCalendar = Calendar.getInstance();
//        outCalendar.setTime (tmpDate);
//        return outCalendar;
//    } /*end method getExtremeStockDBTradeDate */
    public static Calendar getExtremeStockDBTradeDate (DBase dbaseParam,
                                                       String sStockDB,
                                                       String sTradeDate,
                                                       String sExtreme) throws Exception
    {
        if (dbaseParam == null)
            throw new Exception ("null dbase.");

        Vector vStockTables = dbaseParam.showTables(); //DBase.showTables (connectionParam, sStockDB);

        if (vStockTables == null) {
            throw new Exception ("vStockTables == null");
        }
        String sBeginDate = null;

        if (vStockTables.size() >= 1) {
            int iIdx = 0;
            String sPrevBeginDate = null;
            do {
                String sStockName = vStockTables.get (iIdx).toString ();
//                ResultSet resultSet =  statement.executeQuery ("SELECT " + sTradeDate +
//                                                               " FROM " + sStockName +
//                                                               " ORDER BY " + sTradeDate + " " + sExtreme +
//                                                               " LIMIT 1;");
                Connection connection = dbaseParam.getDBHost().getConnection();
//    public static ResultSet getQuery (Connection connectionParam, 
//                                      String     sDBName, 
//                                      String     sSelectColumn, 
//                                      String     sFromTable, 
//                                      String     sWhereCondition, 
//                                      String     sOrderBy) throws Exception
//ORIG                ResultSet resultSet = Table.getQuery(connection, sTradeDate, sStockName, DBase.SQL_TRUE, sTradeDate + " " + sExtreme, " 1 ");
                ResultSet resultSet = Table.getQuery(connection, sStockDB, sTradeDate, sStockName, DBase.SQL_TRUE, sTradeDate + " " + sExtreme, " 1 "); //sTradeDate, sStockName, DBase.SQL_TRUE, sTradeDate + " " + sExtreme, " 1 ");
                if (resultSet.getWarnings() == null) {
                    resultSet.first();
                    sBeginDate     = resultSet.getString (sTradeDate).toLowerCase();
                    if (iIdx == 0) {
                        sPrevBeginDate = sBeginDate;
                    }
                    if (sPrevBeginDate.equals(sBeginDate) == false) {
                        String sPrevStockName = null;
                        if (iIdx > 0)
                            sPrevStockName = (String) vStockTables.get (iIdx -1);
                        String sErrMsg = "Inconsistent tradeDate index columns on " + sStockDB + " DB; " +
                                         "date found on " + sPrevStockName + ": " + sPrevBeginDate + ", " +
                                         "date found on " + sStockName     + ": " + sBeginDate + ".";
                        throw new Exception (sErrMsg);
                    }
                    sPrevBeginDate = sBeginDate;
                }
                else {
                    SQLWarning sqlWarning =resultSet.getWarnings();
                    String sWarningMsg = sqlWarning.getMessage();
                    throw new Exception (sWarningMsg);
                }
                iIdx++;
            } while (iIdx < vStockTables.size ());
        }
        else {
            throw new Exception ("vStockTables.size < 1.");
        }

        Date tmpDate = java.sql.Date.valueOf (sBeginDate);

        Calendar outCalendar = Calendar.getInstance();
        outCalendar.setTime (tmpDate);
        return outCalendar;
    } /*end method getExtremeStockDBTradeDate */    
    /**
     *
     *
     */
//    static public boolean isProject (Connection connectionParam, String sDBName) throws Exception
//    {
//        if (DBase.useDB(connectionParam, sDBName) == false) {
//            return false;
//        }
//        Vector vTables = DBase.showTables(connectionParam, sDBName);
//        if (vTables == null) {
//            return false;
//        }
//        if (!vTables.contains        (InputAttribs.TABLE_NAME)) {
//            return false;
//        } else if (!vTables.contains (ExcludeTables.TABLE_NAME)) {
//            return false;
//        } else if (!vTables.contains (ExcludeColumns.TABLE_NAME)) {
//            return false;
//        } else if (!vTables.contains (TimeLine.TABLE_NAME)) {
//            return false;
//        } else if (!vTables.contains (OptionalAttributes.TABLE_NAME)) {
//            return false;
//        } else if (!vTables.contains (StockExperiments.TABLE_NAME)) {
//            return false;
//        }
//        return true;
//    }
    /*
     * 
     * 
     */
    static public boolean isProject (DBase dbaseParam) throws Exception
    {
        if (dbaseParam == null) {
            return false;
        }
        //////////////////////////////////////////////////////////
        Vector vTables = dbaseParam.showTables();
        if (vTables == null) {
            return false;
        }
        if (!vTables.contains        (InputAttribs.TABLE_NAME)) {
            return false;
        } else if (!vTables.contains (ExcludeTables.TABLE_NAME)) {
            return false;
        } else if (!vTables.contains (ExcludeColumns.TABLE_NAME)) {
            return false;
        } else if (!vTables.contains (TimeLine.TABLE_NAME)) {
            return false;
//        } else if (!vTables.contains (OptionalAttributes.TABLE_NAME)) {
//            return false;
        } else if (!vTables.contains (StockExperiments.TABLE_NAME)) {
            return false;
        }
        return true;
        //////////////////////////////////////////////////////////
//        return isProject (dbaseParam.getDBHost().getConnection(), sDBName);
    }
    /*
     * 
     * 
     */
    static public boolean hasOptionalAtttibs (DBase dbaseParam)
    {
        if (dbaseParam == null) {
            return false;
        }
        //////////////////////////////////////////////////////////
        Vector vTables = dbaseParam.showTables();
        if (vTables == null) {
            return false;
        }
        if (vTables.contains (OptionalAttributes.TABLE_NAME)) {
            return true;
        }
        return false;
    }
    /**
     *
     *
     */
    public DBase getProjectDBase ()
    {
        return projectDBase;
    }
}
